import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/home_controller.dart';

class HomeView extends GetView<HomeController> {
  const HomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //记得用obx包裹
    return Obx(() => Scaffold(
          body: Center(
            child: PageView(
              controller: controller.pageController,
              onPageChanged: (index) {
                controller.setCurrentIndex(index);
              },
              children: controller.pageViews,
            ),
          ),
          //设置底部的BottomNavigationBar
          bottomNavigationBar: BottomNavigationBar(
            fixedColor: Colors.red,
            //选中的颜色
            type: BottomNavigationBarType.fixed,
            currentIndex: controller.currentIndex.value,
            //item点击事件
            onTap: (index) {
              controller.setCurrentIndex(index);
              //点击的时候，切换pageview
              controller.pageController.jumpToPage(index);
            },
            items: const [
              BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
              BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
              BottomNavigationBarItem(icon: Icon(Icons.room_service), label: "服务"),
              BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: "购物车"),
              BottomNavigationBarItem(icon: Icon(Icons.people), label: "我的")
            ],
          ),
        ));
  }
}
